package ysq.weixin.model.info;

import net.sf.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * 消息builder工具类
 */
public class WxMessageBuilder {

	//客服文本消息
	public static String prepareCustomText(String openid, String content){
		JSONObject jsObj = new JSONObject();
		jsObj.put("touser", openid);
		jsObj.put("msgtype", MsgType.Text.name());
		JSONObject textObj = new JSONObject();
		textObj.put("content", content);
		jsObj.put("text", textObj);
		return jsObj.toString();
	}

	//客服信息，json转map<String,String>
	public static Map<String,String> customTextToMap(String json){
		HashMap<String,String> data=new HashMap<String,String>();
		JSONObject jsonObject=JSONObject.fromObject(json);
		Iterator it=jsonObject.keys();
		while (it.hasNext()){
			String key= String.valueOf(it.next());
			String value=(String)jsonObject.get(key);
			data.put(key,value);
		}
		return data;
	}


}
